<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Storage;

class OrderResource extends JsonResource
{
    /**
     * @param Request $request
     * @return array
     */
    public function toArray($request)
    {
        $project = json_decode($this->project_info, true);
        return [
            'id' => $this->id,
            'order_no' => $this->order_no,
            'pay_time' => $this->pay_time ?: '',
            'pay' => $this->pay,
            'title' => $project['title'],
            'image' => Storage::disk('public')->url($project['image']),
            'describe' => $project['describe'],
            'date' => $project['date'],
            'address' => $project['address'],
            'money' => $this->money,
            'created_at' => $this->created_at->toDateString()
        ];
    }
}
